package com.example.hzq.food.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.hzq.food.R;
import com.example.hzq.food.bean.FoodBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hzq on 2017/6/28.
 */

public class Buydetailadapter extends RecyclerView.Adapter{
    private Context context;
    public List<FoodBean> foods=new ArrayList<>();;
    public List<Integer> count=new ArrayList<>();;
    private LayoutInflater layoutInflater;
    public Buydetailadapter(Context c, List<FoodBean> i,List<Integer> count){
        this.context=c;
        this.foods.addAll(i);
        this.count.addAll(count);
        this.layoutInflater=LayoutInflater.from(context);
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        public TextView foodsname,number,price;
        public ViewHolder(View itemView){
            super(itemView);
            foodsname=(TextView)itemView.findViewById(R.id.buyfoodname);
            number=(TextView)itemView.findViewById(R.id.buyfoodnum);
            price=(TextView)itemView.findViewById(R.id.buyfoodsum);
        }
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = layoutInflater.inflate(R.layout.item_buy, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final FoodBean food;
        if(foods!=null)
        {
            food = this.foods.get(position);
           this.count.get(position);
            if (food == null)
                return;
            final ViewHolder viewholder = (ViewHolder) holder;
            viewholder.foodsname.setText(food.getFoodname());
            viewholder.number.setText(count.get(position)+"");
            viewholder.price.setText(count.get(position)*food.getPrice()+"");
        }
    }
    @Override
    public int getItemCount() {
        if (foods != null)
            return foods.size();
        else return 0;
    }
}
